

/* Bring in data from 1_Data_Cleaning.do */
clear all
use "data/outputs/clean_mm.dta", clear 


/* Define likelihood function */
program define mylikelihood
	args lnf s1 s2 s3 s4 s5 s6
	local totp = 1 + exp(`s1') + exp(`s2') + exp(`s3') + exp(`s4') + exp(`s5') + exp(`s6') 
	forvalue i = 1(1)6 {
	local p`i' = exp(`s`i'') / `totp'
	}
	local p7 = 1 / `totp'
	quietly replace `lnf' = ln(`p1' + `p2' + `p3') if $ML_y1 == 0 & $ML_y2 == 0 & $ML_y3 == 0  
	quietly replace `lnf' = ln(`p4' + `p5') if $ML_y1 == 0 & $ML_y2 == 1 & $ML_y3 == 0  
	quietly replace `lnf' = ln(`p6') if $ML_y1 == 1 & $ML_y2 == 0 & $ML_y3 == 0 
	quietly replace `lnf' = ln(`p7') if $ML_y1 == 1 & $ML_y2 == 1 & $ML_y3 == 0 
	quietly replace `lnf' = ln(`p3') if $ML_y1 == 0 & $ML_y2 == 0 & $ML_y3 == 1
	quietly replace `lnf' = ln(`p4') if $ML_y1 == 0 & $ML_y2 == 1 & $ML_y3 == 1
	quietly replace `lnf' = ln(`p2' + `p6') if $ML_y1 == 1 & $ML_y2 == 0 & $ML_y3 == 1 
	quietly replace `lnf' = ln(`p1' + `p5' + `p7') if $ML_y1 == 1 & $ML_y2 == 1 & $ML_y3 == 1 
end


/* Make outcome variables binary */
gen exp2_support_binary = 0 if exp2_support >= 1 & exp2_support <= 2
replace exp2_support_binary = 1 if exp2_support >= 3 & exp2_support <= 4

label variable exp2_support_binary "Support governor's plan?"
label define exp2_support_binaryl 1 "Support Plan", replace
label define exp2_support_binaryl 0 "Oppose Plan", add
label values exp2_support_binary exp2_support_binaryl

gen exp2_consistent_binary = 0 if exp2_consistent >= 1 & exp2_consistent <= 2
replace exp2_consistent_binary = 1 if exp2_consistent >= 3 & exp2_consistent <= 4

label variable exp2_consistent_binary "Governor's plan democratic?"
label define exp2_consistent_binaryl 1 "Consistent w/ democracy", replace
label define exp2_consistent_binaryl 0 "Inconsistent w/ democracy", add
label values exp2_consistent_binary exp2_consistent_binaryl


**-------------**
** Full sample **
**-------------**


/* get ML estimates */
ml model lf mylikelihood (s1: exp2_support_binary =)(s2: exp2_consistent_binary =) /*
*/ (s3: copartisan =) /s4 /s5 /s6
ml maximize


/* normalize */
matrix s = e(b)
local tots = 1
forvalues i = 1(1)6 {
local tots = `tots' + exp(s[1, `i'])
}
matrix p = J(1, 7, -9)
forvalues i = 1(1)6 {
matrix p[1, `i'] = exp(s[1, `i']) / `tots'
}
matrix p[1, 7] = 1 / `tots'


/* show results */
matlist p


**---------------------**
** Democracy Index > 0 **
**---------------------**


/* get ML estimates */
ml model lf mylikelihood (s1: exp2_support_binary =)(s2: exp2_consistent_binary =) /*
*/ (s3: copartisan =) /s4 /s5 /s6 if dem_index >= 0 & missing(dem_index) ~= 1 
ml maximize


/* normalize */
matrix s = e(b)
local tots = 1
forvalues i = 1(1)6 {
local tots = `tots' + exp(s[1, `i'])
}
matrix p = J(1, 7, -9)
forvalues i = 1(1)6 {
matrix p[1, `i'] = exp(s[1, `i']) / `tots'
}
matrix p[1, 7] = 1 / `tots'


/* show results */
matlist p



**---------------------**
** Democracy Index < 0 **
**---------------------**


/* get ML estimates */
ml model lf mylikelihood (s1: exp2_support_binary =)(s2: exp2_consistent_binary =) /*
*/ (s3: copartisan =) /s4 /s5 /s6 if dem_index < 0 & missing(dem_index) ~= 1 
ml maximize


/* normalize */
matrix s = e(b)
local tots = 1
forvalues i = 1(1)6 {
local tots = `tots' + exp(s[1, `i'])
}
matrix p = J(1, 7, -9)
forvalues i = 1(1)6 {
matrix p[1, `i'] = exp(s[1, `i']) / `tots'
}
matrix p[1, 7] = 1 / `tots'


/* show results */
matlist p


/* End */
